package com.znsb.msfq.activity;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.znsb.msfq.BaseActivity;
import com.znsb.msfq.R;
import com.znsb.msfq.utils.ToastUtils;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @name：
 * @author： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/10
 * @modifyTime： 2017/2/10
 * @explain：
 */

public class HelpCenterActivity extends BaseActivity {
    @Bind(R.id.bar_img_back)
    ImageView barImgBack;
    @Bind(R.id.bar_tv_title)
    TextView barTvTitle;
    @Bind(R.id.bar_tv_other)
    TextView barTvOther;
    @Bind(R.id.help_lin_layout1)
    LinearLayout helpLinLayout1;
    @Bind(R.id.help_lin_layout2)
    LinearLayout helpLinLayout2;
    @Bind(R.id.help_tv_copy)
    TextView helpTvCopy;
    @Bind(R.id.help_lin_layout3)
    LinearLayout helpLinLayout3;
    @Bind(R.id.help_tv_servicerule)
    TextView helpTvServicerule;
    @Bind(R.id.help_tv_shoprule)
    TextView helpTvShoprule;
    @Bind(R.id.help_lin_layout4)
    LinearLayout helpLinLayout4;

    @Override
    protected int getlayoutView() {
        return R.layout.act_help_center;
    }

    @Override
    protected void initView(View view) {
        barTvTitle.setText("联系客服");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void clickListener(View view) {

    }


    @OnClick({R.id.bar_img_back, R.id.help_lin_layout1, R.id.help_lin_layout2, R.id.help_tv_copy, R.id.help_lin_layout3, R.id.help_tv_servicerule, R.id.help_tv_shoprule})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bar_img_back:
                finish();
                break;
            case R.id.help_lin_layout1:
                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" +this.getResources().getString(R.string.service_tel));
                intent.setData(data);
                startActivity(intent);
                break;
            case R.id.help_lin_layout2:
                if (!isQQClientAvailable(HelpCenterActivity.this)) {
                    ToastUtils.TextToast(HelpCenterActivity.this,"请下载安装QQ",2000);
                } else {
                    //Android打开手机QQ与指定用户聊天界面
                    String urls = "mqqwpa://im/chat?chat_type=wpa&uin=1377312585";
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urls)));
                }
                break;
            case R.id.help_tv_copy:
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText("mashangfenqi");
                ToastUtils.TextToast(this, "复制成功", 2000);
                break;
            case R.id.help_lin_layout3:
                break;
            case R.id.help_tv_servicerule:
                break;
            case R.id.help_tv_shoprule:
                break;
        }
    }
    /**
     * 判断qq是否可用
     *
     * @param context
     * @return
     */
    public static boolean isQQClientAvailable(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                if (pn.equals("com.tencent.mobileqq")) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


}
